<% %>
<div id="print" style="font-size:12px;text-align:right;width:100%">
<a href="javascript:window.print();"><%=image_tag"printer.gif",:border=>0,:alt=>'To preview the print result, use File-> Print Preview'.t%><%='Print'.t%></a>
</div>
<table class="TimeTrack">
 <tr>
     <td><%='Report Time Zone'.t%></td>
     <td colspan=2>
     <%=@start_at%> - <%=@end_at%>
     </td>
 </tr>
 <tr>
     <td><%='Selected users'.t%></td>
     <td style="white-space:normal" colspan=2>
       <%@users.each do |u|%>
	     <%=link_to u.name,:controller=>'user',:action=>'show',:id=>u.id%>
       <%end%>
     </td>
 </tr>
 <tr>
   <td><%='Confirm Type'.t%>:</td>
	<td colspan=2><%=@confirmed_time.t%></td>
 </tr>
 <tr>
   <td><%='Work Type'.t%>:</td>
	<td colspan=2><%=@work_time.t%></td>
 </tr>
 <tr>
     <td><%='Include Completed Projects'.t%></td>
	 <td><%= @include_completed_projects == "1" ? "Yes".t : "No".t%>
<tr>
   <th><%='Username'.t%></th>
   <th align=left><span style="width:120px"><%='Project name'.t%></span><%='Hours'.t%></th>
 </tr>
 <%
  p_count = 0
  p_total = 0
  user_total_hours = 0 
 %>
 <%@users.each do |user|%>

 <tr>
   <td valign=top width=20%>
      <%=link_to user.name,:controller=>"user",:action=>'show',:id=>user.id%>
   </td>
   <td width=80%> 
       <%user_total_hours = user.total_hours(user.id,@start_at,@end_at,@confirmed_time,@work_time) %>
       <%if @include_completed_projects == "1"%>
       <%@projects = user.projects%>
	   <%else%>
       <%@projects = user.active_projects%>
	   <%end%>
	   <table style="border-collapse:collapse" width=100%>
       <%@projects.each do |p|%>
	       <%ut = p.hours(user.id,@start_at,@end_at,@confirmed_time,@work_time)%>
		 <tr>
		   <td valign=top><%=link_to p.name,:controller=>'project',:action=>'show',:id=>p.id%></td>
		   <td align=right width=40%>
		    <%if ut > 0%>
			 <table style="border-collapse:collapse;width:100%">
		     <%any_type = ut%>
	         <%p.activity_types.each do |a|%>
		      <%uat = p.hours(user.id,a.id,@start_at,@end_at,@confirmed_time,@work_time)%>
			   <%if uat >0%>
                 <tr><td><%=a.name%>:</td><td align=right><%=sprintf('%0.2f',(uat))%></td></tr>
			   <%end%>
		      <%any_type = any_type - uat%>
		     <%end%> 
		     <tr><td style="border-bottom:2px #ccc solid"><%='ANY type'.t%>:</td><td style="border-bottom:2px #ccc solid" align=right><%=sprintf('%0.2f',any_type)%></td></tr>
		     <tr><td width=50% style="border-bottom:0px" align=right><%='Part Total'.t%>:</td><td style="text-align:right;border-bottom:0px;font-weight:bold"><%= sprintf('%0.2f',ut)%></td></tr>
			 </table>
		  <%end%>
		  </td>
		  <td valign=bottom align=right style="padding:2px;padding-bottom:10px;" width=150>
		   <%=user_total_hours == 0 ? 0 : sprintf("%0.2f",ut*100/user_total_hours)%>%
	         <span style="width:102px;padding:0px;height:10px;background:#ccc;border:1px #666 solid;text-align:left">
		     <span style="width:<%=user_total_hours == 0 ? 0 : ut*100/user_total_hours%>px;background:#666"> </span>
		    </span>
		   </td>
		  </tr>
	   <%end%>
	   <tr>
	     <td></td>
		 <td align=right>
			<table style="border-collapse:collapse;width:100%">
		     <tr>
			   <td align=right width=50% style="border-top:2px #666 solid;border-bottom:0px"><%="Total".t%>:</td>
			   <td align=right  style="border-top:2px #666 solid;border-bottom:0px"><%=sprintf('%0.2f',user_total_hours)%></td>
			 </tr>
		   </table>
		 </td>
		 <td></td>
	   </table>
   </td>
 </tr>
 <%
   p_count += 1
   p_total += user_total_hours 
 %>
 <%end%>
 <tr class=th>
  <td><%='Users'.t%>:<%=p_count%></td>
  <td colspan=2><%='Total hours'.t%>:<%=sprintf("%0.2f",p_total)%></td>
 </table>
